<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/29
 * Time: 22:45
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Http\Models\ResourceModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ResourceController extends Controller
{
    public function index(){
        $res = DB::table('resource')->paginate(15);
        return $res;
    }
    public function store(Request $request){
//        $cate=new CateModel();
//        $res=$cate->save($request->all());
        $data=$request->all();
//        dd($data);
        $res=ResourceModel::create($data);
        $data=[];
        if($res){
            $data['msg']='添加成功';
            return  $data;
        }else{
            $data['msg']='添加失败';
            return  $data;
        }
    }

    //删除
    public function destroy(Request $request){
        $id=$request->input('id');
        $deleted = DB::delete('delete from resource where id = ? ', [$id]);
        $data=[];
        if($deleted){
            $data['msg']='删除成功';
            $data['code']=1;
            return  $data;
        }else{
            $data['code']=0;
            $data['msg']='删除失败';
            return  $data;
        }

    }

    //修改
    public function update(Request $request){
        $data=$request->all();
        $res= ResourceModel::where('id',$request->input('id'))->update($data);
        $data=[];
        if($res){
            $data['msg']='修改成功';
            return  $data;
        }else{
            $data['msg']='修改失败';
            return  $data;
        }
    }

}